<template>
  <div class="rankingLeft">
    <span>云音乐特色榜</span>
    <!-- 榜单类别 -->
    <div
      v-for="(category, index) in categoryList.slice(0, 4)"
      :key="category.id"
      class="rankingItem"
      :class="currentIndex === index ? 'active' : ''"
      @click="handleChangeCategory(index, category)"
    >
      <img class="rankingImg" :src="category.coverImgUrl" />
      <div class="rankingTitle">
        <div>{{ category.name }}</div>
        <div class="rankingTitleBottom">{{ category.updateFrequency }}</div>
      </div>
    </div>
    <span>全球媒体榜</span>
    <!-- 榜单类别 -->
    <div
      v-for="(category, index) in categoryList.slice(4)"
      :key="category.id"
      class="rankingItem"
      :class="currentIndex === index + 4 ? 'active' : ''"
      @click="handleChangeCategory(index + 4, category)"
    >
      <img class="rankingImg" :src="category.coverImgUrl" />
      <div class="rankingTitle">
        <div>{{ category.name }}</div>
        <div class="rankingTitleBottom">{{ category.updateFrequency }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState, mapActions, mapMutations } from 'vuex'

export default {
  name: 'RankingCategory',
  data() {
    return {
      // 当前选中榜单的种类
      currentIndex: 0
    }
  },
  computed: {
    ...mapState('ranking', ['categoryList'])
  },
  methods: {
    ...mapActions('ranking', ['getRankingDetail']),
    ...mapMutations('ranking', ['UPDATE_FREQUENCY']),
    // 点击改变排行榜展示类别
    handleChangeCategory(index, category) {
      const { id, updateFrequency } = category
      this.currentIndex = index
      this.getRankingDetail(id)
      this.UPDATE_FREQUENCY(updateFrequency)
    }
  }
}
</script>

<style lang="less" scoped>
// 左侧栏样式开始
.rankingLeft {
  padding-top: 30px;
  height: 100%;
  span {
    margin-left: 15px;
    height: 40px;
    line-height: 40px;
    font-size: 14px;
    font-family: simsun, \5b8b\4f53;
    font-weight: 600;
  }
  .rankingItem {
    display: flex;
    align-items: center;
    width: 250px;
    height: 60px;
    cursor: pointer;
    &.active {
      background: #e6e6e6;
    }
    .rankingImg {
      margin-left: 20px;
      height: 40px;
      width: 40px;
    }
    .rankingTitle {
      display: flex;
      flex-wrap: wrap;
      align-content: space-between;
      margin-left: 10px;
      height: 40px;
      width: 160px;
      div {
        width: 160px;
      }
      .rankingTitleBottom {
        color: #999999;
      }
    }
  }
}
// 左侧栏样式结束
</style>
